
def calculateDiaryScore(diaryContent, chooseEmo):
    from snownlp import SnowNLP
    import math

    # 20分基础分，其余为80分
    # 表情得分默认占比因子2，文本的占比因子：日记的句子数以及负面情绪在句子中的占比
    emo_score_map = {'angel': '5', 'angry': '5', 'blink': '25', 'confused': '10', 'cool-1': '20', 'cool': '25', 'corpse': '5', 'cry-1': '10', 'cry': '10', 'devil': '15', 'dizzy': '10', 'expressionless-1': '20', 'expressionless': '15', 'fall-ill': '15', 'haha-1': '20', 'haha': '20', 'happy-1': '15', 'happy-2': '20', 'happy-3': '20', 'injured': '5', 'jealous': '25', 'kiss-1': '25', 'kiss-2': '25', 'kiss': '25', 'laughcry': '25', 'love': '25', 'lue-1': '20', 'lue-2': '25', 'lue': '20', 'mask': '15', 'muddleb': '20', 'mute': '15', 'poisoning-1': '5', 'poisoning': '10', 'sad-1': '5', 'sad-2': '10', 'shocked-1': '15', 'beshocked': '20', 'shut-up': '10', 'sleep': '15', 'sly-smile': '25', 'smile-1': '5', 'squint': '10', 'sweating': '5', 'thinking': '10', 'tired': '10', 'worry-1': '15', 'worry': '15', 'yue-1': '5', 'yue': '5'}

    s = SnowNLP(diaryContent)
    total_sentences_num = len(s.sentences)
    bad = 0.0
    sum_text_score = 0.0
    for sentence in s.sentences:
        if SnowNLP(sentence).sentiments < 0.5:
            bad = bad + 1
        # print(SnowNLP(sentence).sentiments)
        sum_text_score = sum_text_score + min(((SnowNLP(sentence).sentiments * 100 ) + 10), 100)

    x = int(emo_score_map[chooseEmo]) / 25 * 100
    x_rate = 3
    y = sum_text_score / total_sentences_num
    y_rate = min(total_sentences_num, 3 + math.log(total_sentences_num)) + (bad / total_sentences_num) * 10
    total_rate = x_rate + y_rate

    total_score = 20 + 80 * ( x * (x_rate / total_rate) + y * (y_rate / total_rate)) * 0.01
    # print(int(total_score))
    return int(total_score)



def get_current_week():
    import datetime
    monday, sunday = datetime.date.today(), datetime.date.today()
    one_week = datetime.timedelta(days=7)
    one_day = datetime.timedelta(days=1)
    print(one_day)
    print(monday.weekday())
    while monday.weekday() != 0:
        monday -= one_day
    while sunday.weekday() != 6:
        sunday += one_day

    # return monday, sunday
    # 返回时间字符串
    return datetime.datetime.strftime(monday, "%Y-%m-%d"), datetime.datetime.strftime(sunday, "%Y-%m-%d")

def get_week_date(before_week):
    import datetime
    from datetime import timedelta

    now = datetime.datetime.now()
    this_week_start = now - timedelta(days=now.weekday())
    this_week_end = now + timedelta(days=6 - now.weekday())
    week_start = this_week_start - timedelta(7 * before_week)
    week_end = this_week_end - timedelta(7 * before_week)
    return week_start, week_end

def get_month_date(year_num, month_num):
    import datetime
    from datetime import timedelta

    month_start = datetime.datetime(year_num, month_num, 1)
    if month_start.month == 12:
        month_end = datetime.datetime(year_num+1, 1, 1) - timedelta(days=1)
    else:
        month_end = datetime.datetime(year_num, month_num+1, 1) - timedelta(days=1)
    return month_start, month_end

def get_year_date(year_num):
    import datetime
    from datetime import timedelta

    year_start = datetime.datetime(year_num, 1, 1)
    year_end = datetime.datetime(year_num+1, 1, 1) - timedelta(days=1)
    return year_start, year_end

def convert_to_A():
    emo_score_map = {'angel': '5', 'angry': '5', 'blink': '25', 'confused': '10', 'cool-1': '20', 'cool': '25',
                     'corpse': '5', 'cry-1': '10', 'cry': '10', 'devil': '15', 'dizzy': '10', 'expressionless-1': '20',
                     'expressionless': '15', 'fall-ill': '15', 'haha-1': '20', 'haha': '20', 'happy-1': '15',
                     'happy-2': '20', 'happy-3': '20', 'injured': '5', 'jealous': '25', 'kiss-1': '25', 'kiss-2': '25',
                     'kiss': '25', 'laughcry': '25', 'love': '25', 'lue-1': '20', 'lue-2': '25', 'lue': '20',
                     'mask': '15', 'muddleb': '20', 'mute': '15', 'poisoning-1': '5', 'poisoning': '10', 'sad-1': '5',
                     'sad-2': '10', 'shocked-1': '15', 'beshocked': '20', 'shut-up': '10', 'sleep': '15',
                     'sly-smile': '25', 'smile-1': '5', 'squint': '10', 'sweating': '5', 'thinking': '10',
                     'tired': '10', 'worry-1': '15', 'worry': '15', 'yue-1': '5', 'yue': '5'}


def read_file():
    file_path = 'D:\\Program Files\\JetBrains\\PyCharm 2021.3.3\\pythonProject\\woZaiFlaskProject\\微博.txt'
    sentences_list = []
    # with open(file_path, 'r' ,encoding='utf-8') as f:
    #     for line in f:
    #         sentence = line.split()[0]
    #         author = line.split()[1]
    #         tmp = [sentence, author]
    #         sentences_list.append(tmp)
    #         # print(sentence, author)
    # file_path = 'D:/Program Files/JetBrains/PyCharm 2021.3.3/pythonProject/woZaiFlaskProject/名言.txt'
    # with open(file_path, 'r', encoding='utf-8') as f:
    #     for line in f:
    #         sentence_list = line.split()[0].split('——')
    #         sentence = sentence_list[0]
    #         author = '' if len(sentence_list) == 1 else sentence_list[1]
    #         tmp = [sentence, author]
    #         sentences_list.append(tmp)
    # return sentences_list
    # f2 = open("D:\\Program Files\\JetBrains\\PyCharm 2021.3.3\\pythonProject\\woZaiFlaskProject\\微博.txt",
    #           "a", encoding='utf-8')  # 利用追加模式,参数从w替换为a即可
    # with open(file_path, 'r', encoding='utf-8') as f:
    #     for line in f:
    #         sentence_list = line.split(',')
    #         f2.write(sentence_list[2])
    #         f2.write('\n')
    #         sentences_list.append(sentence_list[2])
    #     f.close()

    # return sentences_list

    with open(file_path, 'r', encoding='utf-8') as f:
        for line in f:
            sentence_list = line.split()
            if len(sentence_list) == 1:
                sentences_list.append(sentence_list[0])
        f.close()

    return sentences_list
            # print(sentence, author)


if __name__ == '__main__':
    # print(get_week_date(3))
    # print(get_month_date(2022, 2))
    # print(get_year_date(2022))
    print(read_file())

